package server.demo.entity;

import jakarta.persistence.*;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.DecimalMin;
import jakarta.validation.constraints.Size;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;

@Entity
@Table(name = "equipment")
public class Equipment {
    
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    
    @NotBlank(message = "设备名称不能为空")
    @Size(max = 200, message = "设备名称长度不能超过200个字符")
    @Column(nullable = false, length = 200)
    private String name;
    
    @Size(max = 100, message = "品牌长度不能超过100个字符")
    @Column(length = 100)
    private String brand;
    
    @Size(max = 100, message = "型号长度不能超过100个字符")
    @Column(length = 100)
    private String model;
    
    @Column(name = "category_id")
    private Long categoryId;
    
    @Column(columnDefinition = "TEXT")
    private String description;
    
    @Column(columnDefinition = "TEXT")
    private String specifications;
    
    @NotNull(message = "日租金不能为空")
    @DecimalMin(value = "0.01", message = "日租金必须大于0")
    @Column(name = "daily_rent_price", precision = 10, scale = 2, nullable = false)
    private BigDecimal dailyRentPrice;
    
    @Enumerated(EnumType.STRING)
    @Column(length = 20)
    private EquipmentStatus status = EquipmentStatus.AVAILABLE;
    
    @Size(max = 500, message = "图片URL长度不能超过500个字符")
    @Column(name = "image_url", length = 500)
    private String imageUrl;
    
    @Column(name = "purchase_date")
    private LocalDate purchaseDate;
    
    @Column(name = "purchase_price", precision = 10, scale = 2)
    private BigDecimal purchasePrice;
    
    @CreationTimestamp
    @Column(name = "created_at", updatable = false)
    private LocalDateTime createdAt;
    
    @UpdateTimestamp
    @Column(name = "updated_at")
    private LocalDateTime updatedAt;
    
    public enum EquipmentStatus {
        AVAILABLE, RENTED, MAINTENANCE, DAMAGED
    }
    
    public Equipment() {}
    
    public Equipment(String name, String brand, String model, Long categoryId, 
                    String description, String specifications, BigDecimal dailyRentPrice) {
        this.name = name;
        this.brand = brand;
        this.model = model;
        this.categoryId = categoryId;
        this.description = description;
        this.specifications = specifications;
        this.dailyRentPrice = dailyRentPrice;
    }
    
    public Long getId() { return id; }
    public void setId(Long id) { this.id = id; }
    
    public String getName() { return name; }
    public void setName(String name) { this.name = name; }
    
    public String getBrand() { return brand; }
    public void setBrand(String brand) { this.brand = brand; }
    
    public String getModel() { return model; }
    public void setModel(String model) { this.model = model; }
    
    public Long getCategoryId() { return categoryId; }
    public void setCategoryId(Long categoryId) { this.categoryId = categoryId; }
    
    public String getDescription() { return description; }
    public void setDescription(String description) { this.description = description; }
    
    public String getSpecifications() { return specifications; }
    public void setSpecifications(String specifications) { this.specifications = specifications; }
    
    public BigDecimal getDailyRentPrice() { return dailyRentPrice; }
    public void setDailyRentPrice(BigDecimal dailyRentPrice) { this.dailyRentPrice = dailyRentPrice; }
    
    public EquipmentStatus getStatus() { return status; }
    public void setStatus(EquipmentStatus status) { this.status = status; }
    
    public String getImageUrl() { return imageUrl; }
    public void setImageUrl(String imageUrl) { this.imageUrl = imageUrl; }
    
    public LocalDate getPurchaseDate() { return purchaseDate; }
    public void setPurchaseDate(LocalDate purchaseDate) { this.purchaseDate = purchaseDate; }
    
    public BigDecimal getPurchasePrice() { return purchasePrice; }
    public void setPurchasePrice(BigDecimal purchasePrice) { this.purchasePrice = purchasePrice; }
    
    public LocalDateTime getCreatedAt() { return createdAt; }
    public void setCreatedAt(LocalDateTime createdAt) { this.createdAt = createdAt; }
    
    public LocalDateTime getUpdatedAt() { return updatedAt; }
    public void setUpdatedAt(LocalDateTime updatedAt) { this.updatedAt = updatedAt; }
}